package org.bpms.service.admin;

import java.util.Map;
import java.util.UUID;

import org.bpms.model.admin.Slog;

import com.jfinal.aop.Before;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.tx.Tx;

/**
 * 系统操作日志接口
 * @author hupei
 *
 */
public class LogService {
	/**
	 * 记录操作
	 * @param user 账户
	 * @param mark 操作说明
	 */
	@Before(Tx.class)
	public void create(String user , String mark){
		new Slog().set("id", UUID.randomUUID().toString().replaceAll("-", ""))
		.set("author", user).set("mark", mark).save();
	}
	
	/**
	 * 查找操作记录
	 * @param stime
	 * @param etime
	 * @param pageNumber
	 * @param pageSize
	 * @param orderField
	 * @param orderDirection
	 * @param pagemap
	 */
	public void findAll(String stime , String etime , Integer pageNumber,Integer pageSize,
	           String orderField,String orderDirection,Map<String,Object> pagemap){
		StringBuffer sql = new StringBuffer("from slog where 1=1 ");
		if (!stime.equals("")){
			sql.append(" and ctime >='"+stime+"'");
		}
		
		if (!etime.equals("")){
			sql.append(" and ctime <='"+etime+"'");
		}
		sql.append(" order by "+orderField+" "+orderDirection);
		Page<Slog> ps = Slog.me.paginate(pageNumber, pageSize, "select * ", sql.toString());
		pagemap.put("pageSize", ps.getPageSize());//页面大小
		pagemap.put("totalRow", ps.getTotalRow());//总行数
		pagemap.put("pageCurrent", ps.getPageNumber());//当前页号
		pagemap.put("orderField", orderField);//排序列名
		pagemap.put("orderDirection", orderDirection);//排序方式
		pagemap.put("pageData", ps.getList());//页面数据
	}
}
